home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / pygst.py < prev    next >
Encoding:
Python Source  |  2009-02-21  |  2.0 KB  |  64 lines

  1. # -*- Mode: Python; py-indent-offset: 4 -*-
  2. # pygst - Python bindings for the GStreamer multimedia framework.
  3. # Copyright (C) 1998-2002  James Henstridge
  4. #           (C) 2005 Edward Hervey
  5. #
  6. #   pygst.py: pygst version selection code.
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. # USA
  22.  
  23. # This allows parallel installation of gst-python
  24. #
  25. # In order to have backward compatibility
  26.  
  27. import sys
  28. import os.path
  29.  
  30. __all__ = ['require']
  31.  
  32. _pygst_dir = os.path.dirname(__file__) + '/gst-0.10'
  33.  
  34. _pygst_version = '0.10'
  35.  
  36. _pygst_required_version = None
  37.  
  38. class RequiredVersionError(ValueError, AssertionError):
  39.     # AssertionError is subclassed for compatibility reasons.
  40.     pass
  41.  
  42.  
  43. def require(version):
  44.     global _pygst_required_version
  45.  
  46.     if _pygst_required_version != None:
  47.         if _pygst_required_version != version:
  48.             raise RequiredVersionError, "a different version of gst was already required"
  49.         else:
  50.             return
  51.  
  52.     if sys.modules.has_key('gst'):
  53.         raise RequiredVersionError, "pygst.require() must be called before importing gst"
  54.  
  55.     if version != _pygst_version:
  56.         raise RequiredVersionError, "Only version '%s' is available" % _pygst_version
  57.  
  58.     # move the pygst path to the front
  59.     while _pygst_dir in sys.path:
  60.         sys.path.remove(_pygst_dir)
  61.     sys.path.insert(0, _pygst_dir)
  62.     
  63.     _pygst_required_version = version
  64.